<?php
/*
	我的下线
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page_setting');
	$levels=array();
	$fromusers=$_SESSION['uid'];
	for($i=0;$i<2;$i++){
		$level=$i+1;
		if(!$fromusers){
			$levels[$level]=0;
			continue;
		}
		$fromusers=pdo_getall('core_members',array('fromuser'=>$fromusers),array('id'),'id');
		if(!$fromusers){
			$levels[$level]=0;
		}else{
			$fromusers=array_keys($fromusers);
			$levels[$level]=count($fromusers);
		}
		
	}
	$return['levels']=$levels;
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$allmember_num=$this->model('member')->getteamids($_SESSION['uid']);
    $allmember_num=count($allmember_num);
	$return['member']['member_num']=$allmember_num;
	$return['params']=array('page'=>1,'level'=>1);
	$return['psize']=20;
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$level=intval($_RQ['level']);
	if(!$level){
		$level=1;
	}
	$fromusers=$_SESSION['uid'];
	for($i=1;$i<$level;$i++){
		if(!$fromusers){
			break;
		}
		$fromusers=pdo_getall('core_members',array('fromuser'=>$fromusers),array('id'),'id');
		if(!$fromusers){
			break;
		}else{
			$fromusers=array_keys($fromusers);
		}
	}
	if(!$fromusers){
		exi('none');
	}
	$params['fromuser']=$fromusers;
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields' => array('id','fromuser','nickname','avatar','createtime')
	);
	$list=pdo_getlist('core_members',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		$item['member_num']=pdo_count('core_members',array('fromuser'=>$item['id']),'id');
	}
	exi($list);
}
?>